#include "SysAddAdminDialog.h"
#include "ui_SysAddAdminDialog.h"
#include "SysMainForm.h"
#include "SysDAL.h"
#include <QSqlQuery>
#include <QDebug>
#include <QDateTime>
#include <QMessageBox>
addAdmin::addAdmin(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::addAdmin)
{
    ui->setupUi(this);
//    SysAssist::Center(this);
}

addAdmin::~addAdmin()
{
    delete ui;
}
void addAdmin::closeEvent(QCloseEvent *event)
{
    MainForm *R=new MainForm ();
    R->TableRefresh();

}

void addAdmin::on_BtnAdd_clicked()
{
    TypeAdmin info;
    info.AdminId=ui->lineID->text();
    info.PassWd=ui->linePasswd->text();
    info.Name=ui->lineName->text();
    info.Tel=ui->lineTel->text();
    info.IdNumber=ui->lineIDNumber->text();
    info.Age=ui->spinBoxAge->text().toInt();
    //超级管理员1，普通管理员：0
    info.Power=ui->comboBox->currentIndex();
    info.WorkDate=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    if(ui->radioMan->isChecked())
    {
        info.Sex=ui->radioMan->text();

    }
    else if(ui->radioWoman->isChecked())
    {
        info.Sex=ui->radioWoman->text();

    }
    ExecStatus add=SysDBL::AdminReg(info);
    if(add.Status)
    {
        QMessageBox::warning(this,tr("提示"),tr("添加成功,恭喜 %1 成为管理员").arg(info.Name));
    }
    else
    {
        QMessageBox::warning(this,tr("提示"),tr("添加失败，错误反馈如下：\n")+add.StatusInfo);
    }
}


void addAdmin::on_BtnQuit_clicked()
{
    this->close();
}
